<template>
  <!-- 经销商信息查询 -->
  <div>
    <!-- 搜索 -->
    <commonSearch ref="commonFilter" @filterChange="changeHandle" @onCollapse="collapseHandle" />
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef="origin_originInfo_inquire_index_01"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <el-button size="small" type="primary" icon="el-icon-download" @click="downloadExcelFnc">下载</el-button>
      </template>
    </FilterTable>
    <Drawer
      :visible.sync="visibleDrawer"
      title="经销商信息"
      destroyOnClose
      :containerStyle="{ width: '70vw', minWidth: '1000px', height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <dealerForm v-model="initData" @close="drawerClose" />
    </Drawer>
    <Drawer
      :visible.sync="visibleDrawerView"
      title="经销商信息"
      destroyOnClose
      :containerStyle="{ width: '70vw', minWidth: '1000px', height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <dealerFormView v-model="initData" @close="drawerClose" />
    </Drawer>
  </div>
</template>
<script>
import commonSearch from '../commonSearch/index';
import dealerForm from '../dealerForm';
import dealerFormView from '../dealerFormView';
import { dictionary } from '@/utils/dictMixin';
import { region } from '@/api/cms-common/region'; //行政区域
import { exportExcelFile } from '@/utils';
import { getAppId } from '@/assets/js/auth'; //获取登录用户
import { findPage, downloadExcel } from '@/api/cms-api/origin/originInfo';
import * as types from '@/api/cms-api/origin/originInfo/types';
import { DICT_CODE } from '@/api/cms-api/origin/commonDealerType'; //经销商类型工具类

export default {
  name: 'inquireIndexComp',
  mixins: [dictionary, region],
  components: {
    commonSearch,
    dealerForm,
    dealerFormView
  },
  data() {
    return {
      isSelectColumn: false,
      visibleDrawer: false,
      visibleDrawerView: false,
      columns: getAppId() == 'beijing' ? this.creatHeader() : this.creatHeader1(),
      initData: {},
      fetchApi: findPage, //ipa 接口
      // fetchParams: {queryByOrgCode:types.QUERY_BY_ORG_VALUE}, //参数
      fetchParams: {} //参数
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    downloadExcelFnc() {
      const loading = this.$loading(require('@/mock/loading').default);
      this.$refs.commonFilter.$refs.commonTopFilter.excuteFormData(this.$refs.commonFilter.$refs.commonTopFilter.form);
      let fetchParams = this.$refs.commonFilter.$refs.commonTopFilter.form;
      this.$nextTick(() => {
        downloadExcel(fetchParams).then(res => {
          exportExcelFile(res.data, '经销商信息查询');
          loading.close();
        });
      });
    },
    //搜索获取数据
    changeHandle(val) {
      // this.fetchParams = Object.assign({queryByOrgCode:types.QUERY_BY_ORG_VALUE},val);
      this.fetchParams = Object.assign({}, val);
    },
    drawerHandle(row, type) {
      let id = -1;
      if (type != 'add') {
        id = row.dealerAttachId;
      }
      this.initData = {
        type: type, //add/edit/show
        examineType: 'show', //设置主表单内容为只读
        isExamine: false, //打开审核按钮和输入框
        formType: types.DEALER_INFO_FORM_STATUS_QUERY_OEM,
        id: id //表主键
      };
      if (type == 'show') {
        this.visibleDrawerView = true;
      } else {
        this.visibleDrawer = true;
      }
    },
    drawerClose(type) {
      this.visibleDrawer = false;
      this.visibleDrawerView = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.drawerHandle(props.row, 'show')}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'auditStatus',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.auditStatus, '2551')}</span>;
          }
        },
        { title: '公司全称', dataIndex: 'dealerName', sorter: true },
        // { title: '临时代码', dataIndex: 'x1', sorter: true },
        { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
        { title: '经销商简称', dataIndex: 'dealerShortname', sorter: true },
        {
          title: '渠道类型',
          dataIndex: 'dealerType',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.dealerType, DICT_CODE)}</span>;
          }
        },
        {
          title: '经销商级别',
          dataIndex: 'shopLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.shopLevel, '2540')}</span>;
          }
        },
        {
          title: '店面等级',
          dataIndex: 'constructLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.constructLevel, '2554')}</span>;
          }
        }, //SALE_LEVEL？销售店面级别
        {
          title: '展厅级别',
          dataIndex: 'saleLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.saleLevel, '2542')}</span>;
          }
        },
        {
          title: '售后级别',
          dataIndex: 'serviceLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.serviceLevel, '2543')}</span>;
          }
        },
        { title: '销售热线', dataIndex: 'salesLine', sorter: true },
        { title: '销售邮箱', dataIndex: 'salesEmail', sorter: true },
        { title: '销售运营地址', dataIndex: 'salesAddress', sorter: true },
        { title: '销售店经度', dataIndex: 'salesLongitude', sorter: true },
        { title: '销售店纬度', dataIndex: 'salesLatitude', sorter: true },
        {
          title: '燃油车经营状态',
          dataIndex: 'fuelDealerStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '8051')}</span>;
          }
        },
        {
          title: '新能源经营状态',
          dataIndex: 'newenergyDealerStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '8051')}</span>;
          }
        },
        { title: '老DMS代码', dataIndex: 'dealerCodeOld', sorter: true },
        { title: '事业部', dataIndex: 'deptName', sorter: true, width: 200 },
        { title: '办事处', dataIndex: 'officeName', sorter: true },
        {
          title: '省份',
          dataIndex: 'provinceId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.provinceId)}</span>;
          }
        },
        {
          title: '城市',
          dataIndex: 'cityId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.cityId)}</span>;
          }
        },
        {
          title: '县区',
          dataIndex: 'districtId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.districtId)}</span>;
          }
        },
        { title: '系统管理员', dataIndex: 'systemManager', sorter: true },
        { title: '管理员电话', dataIndex: 'sysManagerPhone', sorter: true },
        { title: '保证金金额', dataIndex: 'cashDeposit', numberFormat: true, sorter: true },
        {
          title: '启用标记',
          dataIndex: 'status',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.status, '1003')}</span>;
          }
        },
        {
          title: '经营状态',
          dataIndex: 'dealerStatus',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.dealerStatus, '2552')}</span>;
          }
        },
        {
          title: '是否启用中央补贴',
          dataIndex: 'isRegionalAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isRegionalAllowance, '1004')}</span>;
          }
        },
        {
          title: '是否启用地方补贴',
          dataIndex: 'isCentrelAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isCentrelAllowance, '1004')}</span>;
          }
        },
        {
          title: '开票是否包含地方补贴',
          dataIndex: 'isContainRAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isContainRAllowance, '1004')}</span>;
          }
        },

        {
          title: '建店标准',
          dataIndex: 'constructStandard',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.constructStandard, '2553')}</span>;
          }
        },
        { title: '经销商形式', dataIndex: 'financeCompanyNames', sorter: true },

        { title: '验收通过时间', dataIndex: 'passTime', dateFormat: 'yyyy-MM-dd', sorter: true },
        {
          title: '样板店',
          dataIndex: 'isModelShop',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isModelShop, '1004')}</span>;
          }
        },
        {
          title: '动力电池回收网络',
          dataIndex: 'isPowerRecycing',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isPowerRecycing, '1004')}</span>;
          }
        },
        {
          title: '电池联合服务中心',
          dataIndex: 'batteryServiceStation',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.batteryServiceStation, '1004')}</span>;
          }
        },
        { title: '售后服务热线', dataIndex: 'serviceLine', sorter: true },
        { title: '售后邮箱', dataIndex: 'serviceEmail', sorter: true },
        { title: '24小时服务电话', dataIndex: 'hotLine', sorter: true },
        { title: '售后运营地址', dataIndex: 'serviceAddress', sorter: true },
        { title: '是否黑名单', dataIndex: 'isBlack', sorter: true },
        { title: '财务审核状态', dataIndex: 'isChecked',dictItems:this.createDictList('1022'), sorter: true },
        { title: 'SAP代码（电）', dataIndex: 'sapCode', sorter: true },
        { title: 'SAP代码（油）', dataIndex: 'sapoilCode', sorter: true },
        { title: '创建日期', dataIndex: 'createdAt', dateFormat: 'yyyy-MM-dd', sorter: true }
      ];
    },
    creatHeader1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.drawerHandle(props.row, 'show')}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'auditStatus',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.auditStatus, '2551')}</span>;
          }
        },
        { title: '公司全称', dataIndex: 'dealerName', sorter: true },
        // { title: '临时代码', dataIndex: 'x1', sorter: true },
        { title: '经销商代码', dataIndex: 'dealerCode', sorter: true },
        { title: '经销商简称', dataIndex: 'dealerShortname', sorter: true },
        {
          title: '渠道类型',
          dataIndex: 'dealerType',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.dealerType, DICT_CODE)}</span>;
          }
        },
        {
          title: '经销商级别',
          dataIndex: 'shopLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.shopLevel, '2540')}</span>;
          }
        },
        {
          title: '店面等级',
          dataIndex: 'constructLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.constructLevel, '2554')}</span>;
          }
        }, //SALE_LEVEL？销售店面级别
        {
          title: '展厅级别',
          dataIndex: 'saleLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.saleLevel, '2542')}</span>;
          }
        },
        {
          title: '售后级别',
          dataIndex: 'serviceLevel',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.serviceLevel, '2543')}</span>;
          }
        },
        { title: '销售热线', dataIndex: 'salesLine', sorter: true },
        { title: '销售邮箱', dataIndex: 'salesEmail', sorter: true },
        { title: '销售运营地址', dataIndex: 'salesAddress', sorter: true },
        { title: '销售店经度', dataIndex: 'salesLongitude', sorter: true },
        { title: '销售店纬度', dataIndex: 'salesLatitude', sorter: true },
        {
          title: '燃油车经营状态',
          dataIndex: 'fuelDealerStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '8051')}</span>;
          }
        },
        {
          title: '新能源经营状态',
          dataIndex: 'newenergyDealerStatus',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '8051')}</span>;
          }
        },
        { title: '老DMS代码', dataIndex: 'dealerCodeOld', sorter: true },
        { title: '事业部', dataIndex: 'deptName', sorter: true, width: 200 },
        { title: '办事处', dataIndex: 'officeName', sorter: true },
        {
          title: '省份',
          dataIndex: 'provinceId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.provinceId)}</span>;
          }
        },
        {
          title: '城市',
          dataIndex: 'cityId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.cityId)}</span>;
          }
        },
        {
          title: '县区',
          dataIndex: 'districtId',
          sorter: true,
          render: props => {
            return <span>{this.createRegionText(props.row.districtId)}</span>;
          }
        },
        { title: '系统管理员', dataIndex: 'systemManager', sorter: true },
        { title: '管理员电话', dataIndex: 'sysManagerPhone', sorter: true },
        { title: '保证金金额', dataIndex: 'cashDeposit', numberFormat: true, sorter: true },
        {
          title: '启用标记',
          dataIndex: 'status',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.status, '1003')}</span>;
          }
        },
        {
          title: '经营状态',
          dataIndex: 'dealerStatus',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.dealerStatus, '2552')}</span>;
          }
        },
        {
          title: '是否启用中央补贴',
          dataIndex: 'isRegionalAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isRegionalAllowance, '1004')}</span>;
          }
        },
        {
          title: '是否启用地方补贴',
          dataIndex: 'isCentrelAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isCentrelAllowance, '1004')}</span>;
          }
        },
        {
          title: '开票是否包含地方补贴',
          dataIndex: 'isContainRAllowance',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isContainRAllowance, '1004')}</span>;
          }
        },

        {
          title: '建店标准',
          dataIndex: 'constructStandard',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.constructStandard, '2553')}</span>;
          }
        },
        { title: '经销商形式', dataIndex: 'financeCompanyNames', sorter: true },

        { title: '验收通过时间', dataIndex: 'passTime', dateFormat: 'yyyy-MM-dd', sorter: true },
        {
          title: '样板店',
          dataIndex: 'isModelShop',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isModelShop, '1004')}</span>;
          }
        },
        {
          title: '动力电池回收网络',
          dataIndex: 'isPowerRecycing',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.isPowerRecycing, '1004')}</span>;
          }
        },
        {
          title: '电池联合服务中心',
          dataIndex: 'batteryServiceStation',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.batteryServiceStation, '1004')}</span>;
          }
        },
        { title: '售后服务热线', dataIndex: 'serviceLine', sorter: true },
        { title: '售后邮箱', dataIndex: 'serviceEmail', sorter: true },
        { title: '24小时服务电话', dataIndex: 'hotLine', sorter: true },
        { title: '售后运营地址', dataIndex: 'serviceAddress', sorter: true },
        { title: '是否黑名单', dataIndex: 'isBlack', sorter: true },
        { title: 'SAP代码', dataIndex: 'sapCode', sorter: true },
        { title: '创建日期', dataIndex: 'createdAt', dateFormat: 'yyyy-MM-dd', sorter: true }
      ];
    }
  }
};
</script>

<style lang="less" scoped>
</style>
